package Sequence;

public class Test110 {
}

class Solution0110_1 {
    public boolean isBalanced(TreeNode root) {
        return getLevel(root)!=-1;
    }

    private int getLevel(TreeNode root) {
        if (root == null) return 0;

        int left = getLevel(root.left);
        int right = getLevel(root.right);

        if (left==-1||right==-1) return -1;
        if (Math.abs(left-right)>1) return -1;

        return Math.max(left, right)+1;
    }
}
